package kr.co.skplanet.commute.domain;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.OneToMany;
import javax.persistence.OrderBy;
import javax.persistence.Table;

import org.hibernate.annotations.Type;

@Entity
@Table(name = "BOARD2")
public class Board  implements Serializable{

	private static final long serialVersionUID = 1L;

	@Id
	@GeneratedValue(strategy = GenerationType.AUTO)
	private Long id;
	
	@Column(name = "name")
	private String name;

	@Column(name = "passwd")
	private String passwd;

	@Column(name = "title")
	private String title;
	
	@Column(name = "content")
	@Type(type="text")
	private String content;

	@Column(name = "readcount")
	private int readcount;
	
	@Column(name = "ip")
	private String ip;
	
	@Column(name = "regdate")
	private Date regdate;
	
	@Column(name = "realFilePath1")
	private String realFilePath1;
	
	@Column(name = "realFilePath2")
	private String realFilePath2;
	
	@Column(name = "urlFilePath1")
	private String urlFilePath1;
	
	@Column(name = "urlFilePath2")
	private String urlFilePath2;
	

	@OneToMany(mappedBy = "board", fetch = FetchType.LAZY, cascade = {CascadeType.ALL})
	@OrderBy("regdate ASC" )
	private List<Comment> comments;
	
	public Board(){
		setReadcount(0);
		setRegdate(new Date());
	}

	public Long getId() {
		return id;
	}

	public void setId(Long id) {
		this.id = id;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public String getPasswd() {
		return passwd;
	}

	public void setPasswd(String passwd) {
		this.passwd = passwd;
	}

	public String getTitle() {
		return title;
	}

	public void setTitle(String title) {
		this.title = title;
	}

	public String getContent() {
		return content;
	}

	public void setContent(String content) {
		this.content = content;
	}



	public int getReadcount() {
		return readcount;
	}

	public void setReadcount(int readcount) {
		this.readcount = readcount;
	}

	public String getIp() {
		return ip;
	}

	public void setIp(String ip) {
		this.ip = ip;
	}

	public Date getRegdate() {
		return regdate;
	}

	public void setRegdate(Date regdate) {
		this.regdate = regdate;
	}
	
	

	public List<Comment> getComments() {
		return comments;
	}

	public void setComments(List<Comment> comments) {
		this.comments = comments;
	}
	
	public void addComment(Comment comment){
		if(comments == null){
			comments = new ArrayList<Comment>();
		}
		comments.add(comment);
	}

	public String getRealFilePath1() {
		return realFilePath1;
	}

	public void setRealFilePath1(String realFilePath1) {
		this.realFilePath1 = realFilePath1;
	}

	public String getRealFilePath2() {
		return realFilePath2;
	}

	public void setRealFilePath2(String realFilePath2) {
		this.realFilePath2 = realFilePath2;
	}

	public String getUrlFilePath1() {
		return urlFilePath1;
	}

	public void setUrlFilePath1(String urlFilePath1) {
		this.urlFilePath1 = urlFilePath1;
	}

	public String getUrlFilePath2() {
		return urlFilePath2;
	}

	public void setUrlFilePath2(String urlFilePath2) {
		this.urlFilePath2 = urlFilePath2;
	}

	@Override
	public String toString() {
		return "Board [id=" + id + ", name=" + name + ", passwd=" + passwd
				+ ", title=" + title + ", content=" + content + ", readcount="
				+ readcount + ", ip=" + ip + ", regdate=" + regdate
				+ ", realFilePath1=" + realFilePath1 + ", realFilePath2="
				+ realFilePath2 + ", urlFilePath1=" + urlFilePath1
				+ ", urlFilePath2=" + urlFilePath2 + ", comments=" + comments
				+ "]";
	}



	
}
